package com.example.fruitdemo.controller;

import com.example.fruitdemo.pojo.*;
import com.example.fruitdemo.ruslet.R;
import com.example.fruitdemo.service.GoodService;
import com.example.fruitdemo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/pay")
public class PayController {
    @Autowired
    OrderService orderService;
    //立即购买
    @PostMapping("/buynow")
    public R<String> buynow(@RequestBody CartParams cartParams){
        return orderService.buynow(cartParams.getGoodid(),cartParams.getNumber(),cartParams.getSignalprice(),cartParams.getAuthorization());
    }
    @GetMapping("/goodlist")
    public R<Cart> goodlist(String authorization){
        return orderService.getgoods(authorization);
    }
    @GetMapping("/goodbuynow")
    public R<Cart> goodbuynow(String authorization){return orderService.getGoodBuyNow(authorization);}
    //添加到购物车
    @PostMapping("/tocart")
    public R<String> tocart(@RequestBody CartParams cartParams){
        return orderService.tocart(cartParams.getGoodid(),cartParams.getNumber(),cartParams.getSignalprice(),cartParams.getAuthorization());
    }
    //删除商品
    @DeleteMapping("/{authorization}/{goodid}")
    public R<String> removeGood(@PathVariable("authorization") String authorizatin,@PathVariable("goodid") String id)
    {
       // System.err.println(authorizatin+id);
        return orderService.removeGood(authorizatin,id);
    }
    //提交订单
    @PostMapping("/suborder")
    public R<String> suborder(@RequestBody OrderDto orderDto){
        return orderService.suborder(orderDto);
    }
}
